<?php
/**
 * 有关于我的 的接口，例如我的发布啥的
 */
namespace app\facescore\home;
use app\common\controller\Common;
use think\Db;
class My extends Common
{
    /*
     * 我收到赞赏的总人数
     */
    public function my_reward_person($uid = ''){

        $map = [];
        if($uid != null) {
            $map['uid'] = $uid;
        }else{
            return 0;
        }
        //先循环出所有作品
        $data_list = Db::name('facescore_content')->where($map)->order('id desc')->select();
        $res = 0;
        foreach ($data_list as $key => $value) {
            $res += Db::name('facescore_reward')->where(['content_id' => $data_list[$key]['id'],'status'=>1])->count("distinct uid");
        }
        return $res;
    }

    /*
     * 我收到赞赏的总次数
     */
    public function my_reward_count($uid = ''){

        $map = [];
        if($uid != null) {
            $map['uid'] = $uid;
        }else{
            return 0;
        }
        //先循环出所有作品
        $data_list = Db::name('facescore_content')->where($map)->order('id desc')->select();
        $res = 0;
        foreach ($data_list as $key => $value) {
            $res += Db::name('facescore_reward')->where(['content_id' => $data_list[$key]['id'],'status'=>1])->count();
        }
        return $res;
    }
    /*
    * 我收到赞赏的总钱数
     * uid 用户id
    */
    public function my_reward_money($uid = ''){

        $map = [];
        if($uid != null) {
            $map['uid'] = $uid;
        }else{
            return 0;
        }
        //先循环出所有作品
        $data_list = Db::name('facescore_content')->where($map)->order('id desc')->select();
        $rmb = 0;
        $mag = 0;
        foreach ($data_list as $key => $value) {
            $rmb += Db::name('facescore_reward')->where(['content_id' => $data_list[$key]['id'],'type' => 1,'status' => 1])->sum('money');
            $mag += Db::name('facescore_reward')->where(['content_id' => $data_list[$key]['id'],'type' => 2,'status' => 1])->sum('money');

        }
        $res = ['rmb' => $rmb,'mag' => $mag];
        return json($res);
    }

    /**
     * 他人主页 根据uid 获取其他用户信息
     */
    public function get_userInfo(){
        $data = [];
        $row = Db::name('admin_member')->where(['id' => input('uid')])->field('id,nick,avatar,sex,qianming,home_page_img')->find();
        $data['nickName'] = $row['nick'];
        $data['avatarUrl'] = $row['avatar'];
        $data['gender'] = $row['sex'];
        $data['uid'] = $row['id'];
        $data['qianming'] = $row['qianming'] == null ? '' : $row['qianming'];
        $data['home_page_img'] = $row['home_page_img'] == null ? '' : $row['home_page_img'];
        return json($data);
    }
}